package redis

import (
	"github.com/gogf/gf/util/gconv"
	"strings"
	"time"
	red "github.com/go-redis/redis"
)

var initTime = time.Now().AddDate(-1, -1, -1)

func process(proc func(red.Cmder) error) func(red.Cmder) error {
	return func(cmd red.Cmder) error {
		start := time.Since(initTime)

		defer func() {
			duration := time.Since(initTime) - start
			if duration > slowThreshold {
				var buf strings.Builder
				for i, arg := range cmd.Args() {
					if i > 0 {
						buf.WriteByte(' ')
					}
					buf.WriteString(gconv.String(arg))
				}
				//logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
			}
		}()

		return proc(cmd)
	}
}
